package org.wendu.wdoa.recrep.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wendu.wdoa.common.CurrentUser;
import org.wendu.wdoa.common.Result;
import org.wendu.wdoa.common.WdoaConstants;
import org.wendu.wdoa.common.token.TokenUtils;
import org.wendu.wdoa.newassi.dto.TaskRecDto;
import org.wendu.wdoa.recrep.dto.TRqueryDto;
import org.wendu.wdoa.recrep.model.TackRec;
import org.wendu.wdoa.recrep.service.TaskRecService;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/recrep")
public class TaskRecrepApi {
    @Autowired
    private TaskRecService taskRecService;
    @GetMapping("/getTRList")
    public Result getTaskRec(@RequestHeader(WdoaConstants.HEADER_NAME_TOKEN) String clientToken, TRqueryDto tRqueryDto){
        CurrentUser currentUser = TokenUtils.getCurrentUser(clientToken);
        Map<String,Object> page = taskRecService.getTRList(currentUser.getUserId(),tRqueryDto);
        return Result.OK(page);
    }
    @PostMapping("/recTask")
    public Result recTask(@RequestBody TRqueryDto tRqueryDto){
        taskRecService.recTake(tRqueryDto);
        return Result.OK();
    }
    @PostMapping("/getTaskInformation/{task_id}")
    public Result getTask(@RequestHeader(WdoaConstants.HEADER_NAME_TOKEN) String clientToken,@PathVariable String task_id){
        CurrentUser currentUser = TokenUtils.getCurrentUser(clientToken);
        List<TackRec> list = taskRecService.getTaskInformation(currentUser.getUserId(),task_id);
        return Result.OK(list);
    }
    @PostMapping("/submitTask")
    public Result submitTask(@RequestBody TaskRecDto taskRecDto){
        taskRecService.submitTaskInformation(taskRecDto);
        return Result.OK();
    }
}
